package com.demo.sun.t_sensordata.Base;

/**
 * Created by Sun on 2018/5/25.
 */

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.Toast;

import com.umeng.analytics.MobclickAgent;


public abstract class BaseActivity extends AppCompatActivity {

    protected abstract int getLayoutId();
    protected abstract void initViews();
    protected abstract void initDatas();
    protected abstract void doViews();

    protected InputMethodManager imm;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayoutId());
        imm = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
        initViews();
        initDatas();
        doViews();
    }


    /**
     * 打开软键盘
     */
    public void showInputMethod() {
        imm.toggleSoftInput(0, InputMethodManager.SHOW_FORCED);
    }

    /**
     * 关闭键盘
     */
    public void  hideInputMethod(EditText editText){
        imm.hideSoftInputFromWindow(editText.getWindowToken(), 0); //隐藏
    }
    public void gotoPager(Context context, Class clazz){
        startActivity(new Intent(context,clazz));
    }

    public void gotoPager(Context context,Class clazz,Bundle bundle){
        Intent intent = new Intent(context,clazz);
        if(bundle != null){
            intent.putExtras(bundle);
        }
        startActivity(intent);
    }

    public void shortToast(String text){
        Toast.makeText(this,text,Toast.LENGTH_SHORT).show();
    }




    public void onResume() {
        super.onResume();
        MobclickAgent.onResume(this);
    }
    public void onPause() {
        super.onPause();
        MobclickAgent.onPause(this);
    }


    public void loge(String tag,String msg){
        Log.e(tag,msg);
    }

}
